import { Component, OnInit, Input, TemplateRef, EventEmitter, Output, OnDestroy } from '@angular/core';

export interface StepTitle {
  title: string;
  translate?: string;
  icon?: string | string[] | Set<string> | { [klass: string]: any; } | TemplateRef<void>;
}

@Component({
  selector: 'app-wenyao-steps',
  templateUrl: './wenyao-steps.component.html',
  styleUrls: ['./wenyao-steps.component.scss']
})
export class WenyaoStepsComponent implements OnInit, OnDestroy{

  private _current: number;
  private _direction: string;
  private _stepTitles: StepTitle[];
  private _currentEanble = false;

  @Output()
  currentChange: EventEmitter<number> = new EventEmitter<number>();

  @Input()
  set current(_current: number) {
    this._current = _current;
  }

  get current() {
    return this._current;
  }

  @Input()
  set direction(_direction: string) {
    if (_direction === 'horizontal' || _direction === 'vertical') {
      this._direction = _direction;
    } else {
      throw new Error('direction should be horizontal or vertical');
    }
  }

  get direction() {
    return this._direction;
  }

  @Input()
  set stepTitles(_stepTitles: StepTitle[]) {
    if (_stepTitles) {
      this._stepTitles = _stepTitles;
    }
  }

  get stepTitles() {
    return this._stepTitles;
  }

  @Input()
  set currentEanble(_currentEanble: boolean) {
    this._currentEanble = _currentEanble;
  }

  get currentEanble() {
    return this._currentEanble;
  }

  constructor() {
    this._current = 0;
    this._stepTitles = [];
  }

  changeCurrent(i: number) {
    if (this.currentEanble) {
      console.log(this.currentEanble);
      this.current = i;
      this.currentChange.next(this.current);
    }
  }

  ngOnInit() {
  }

  ngOnDestroy(): void {
     if (this.currentChange) {
       this.currentChange.unsubscribe();
     }
  }

}
